package myapps.ttclient.activity.ppt;

import myapps.ttclient.GlobalVariables;
import myapps.ttclient.Helper;
import myapps.ttclient.R;
import myapps.ttclient.app.TTClientApplication;
import myapps.ttclient.baseclass_and_interface.TTClientMessage;
import myapps.ttclient.baseclass_and_interface.TTClientMessageReceiver;
import myapps.ttclient.protocol.message.powerpoint.PPTCloseAllFilesRequestMessage;
import myapps.ttclient.protocol.message.powerpoint.PPTCloseFileRequestMessage;
import myapps.ttclient.protocol.message.powerpoint.PPTLaunchPowerpointRequestMessage;
import myapps.ttclient.protocol.message.powerpoint.PPTMaximizeWindowRequestMessage;
import myapps.ttclient.protocol.message.powerpoint.PPTMinimizeWindowRequestMessage;
import myapps.ttclient.protocol.message.powerpoint.PPTQuitPowerpointRequestMessage;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;

public class PPTControllingScreenActvity extends Activity 
		implements OnClickListener, TTClientMessageReceiver {

	private TTClientApplication application;
	
	private Button btnLaunchPowerpoint;
	private Button btnQuitPowerpoint;
	
	private Button btnOpenPptFile; 
	
	private Button btnSelectActiveWindow;
	
	private Button btnCloseFile;
	private Button btnCloseAllFiles;
	
	private Button btnMaximizeWindow;
	private Button btnMinimizeWindow;
	
	private Button btnSlideShowScreen;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		
		Helper.updateFullscreenStatus(this, true);
		
		//Helper.keepScreenOn(this);
		
		this.application = (TTClientApplication) this.getApplication();
		
		setContentView(R.layout.ppt_controlling_screen);
	
		btnLaunchPowerpoint = (Button) this.findViewById(R.id.btnLaunchPowerpoint);
		btnLaunchPowerpoint.setOnClickListener(this);
		
		btnQuitPowerpoint = (Button) this.findViewById(R.id.btnQuitPowerpoint);
		btnQuitPowerpoint.setOnClickListener(this);
		
		btnOpenPptFile = (Button) this.findViewById(R.id.btnOpenPptFile);
		btnOpenPptFile.setOnClickListener(this);
		
		btnSelectActiveWindow  = (Button) this.findViewById(R.id.btnSelectActiveWindow);
		btnSelectActiveWindow.setOnClickListener(this);
		
		btnCloseFile = (Button) this.findViewById(R.id.btnCloseFile);
		btnCloseFile.setOnClickListener(this);
		
		btnCloseAllFiles = (Button) this.findViewById(R.id.btnCloseAllFiles);
		btnCloseAllFiles.setOnClickListener(this);
		
		btnMaximizeWindow = (Button) this.findViewById(R.id.btnMaximizeWindow);
		btnMaximizeWindow.setOnClickListener(this);
		
		btnMinimizeWindow = (Button) this.findViewById(R.id.btnMinimizeWindow);
		btnMinimizeWindow.setOnClickListener(this);
		
		btnSlideShowScreen = (Button) this.findViewById(R.id.btnSlideshowScreen);
		btnSlideShowScreen.setOnClickListener(this);
	}
	
	//private ProgressDialog pd;
	
	@Override
	public void onClick(View v) {
		if(btnLaunchPowerpoint == v) {
			this.application.sendMessage(
					new PPTLaunchPowerpointRequestMessage(GlobalVariables.getTemporaryKey()));
			
			  //pd = ProgressDialog.show(v.getContext(), "Working..", "Waiting the server do it.", true,
              //      false);
		
		} else if(btnQuitPowerpoint == v) {
			this.application.sendMessage(
					new PPTQuitPowerpointRequestMessage(GlobalVariables.getTemporaryKey()));
		
		} else if(btnOpenPptFile == v) {
			this.startActivity(
					new Intent(v.getContext(), PPTOpenFileActivity.class));
		
		} else if(btnSelectActiveWindow == v) {
			this.startActivity(
					new Intent(v.getContext(), PPTSelectActiveWindowActivity.class));
		
		} else if(btnMaximizeWindow == v) {
			this.application.sendMessage(
					new PPTMaximizeWindowRequestMessage(GlobalVariables.getTemporaryKey()));
		
		} else if(btnMinimizeWindow == v) {
			this.application.sendMessage(
					new PPTMinimizeWindowRequestMessage(GlobalVariables.getTemporaryKey()));
		
		} else if(btnCloseFile == v) {
			this.application.sendMessage(
					new PPTCloseFileRequestMessage(GlobalVariables.getTemporaryKey()));
			
		} else if(btnCloseAllFiles == v) {
			this.application.sendMessage(
					new PPTCloseAllFilesRequestMessage(GlobalVariables.getTemporaryKey()));
		} else if(btnSlideShowScreen == v) {
			this.startActivity(
					new Intent(v.getContext(), PPTSlideShowScreenActivity.class));
		}

		this.application.vibrate(50);
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		
		this.application.registerMessageReceiver(this);
	}
	
	@Override
	protected void onPause() {
		super.onPause();
		
		this.application.unregisterMessageReceiver(this);
	}

	@Override
	public void receiveMessage(TTClientMessage message) {
//		if(message instanceof DoneMessage)
//		{
//			pd.dismiss();
//		}
	}
}
